﻿using System;
using System.Collections.Generic;
using viBlog.Classes;
using viBlog.Controllers;
using visinia.SmartEngine;
using visinia.SmartEngine.Modules;
using System.Web;

public partial class Modules_viBlog_Categories_CategoryList : WebModule
{
    protected void Page_Load(object sender, EventArgs e)
    {
        /*****************************************************************************************/
        // Post URL = Blog/Category/Category name.aspx
        /*****************************************************************************************/
        // Post RSS feed URL by category = Blog/rss/Category/Category name.aspx
        /**********************************************************************/
        List<Category> list = CategoryController.GetCategories();
        if (list == null)
            return;
        List<Data> DataList = new List<Data>();
        foreach (Category category in list)
        {
            Data data = new Data();
            data.Title = category.Name + " (" + CategoryController.GetCategoryPostsCount(category.CategoryId) + ") ";
            data.Url = WebRoots.GetWebRoot + BlogController.BlogUrlSeparator + "/Category/" + HttpUtility.UrlEncode(category.Name) + ".aspx";
            data.FeedUrl = WebRoots.GetWebRoot + BlogController.BlogUrlSeparator + "/rss/Category/" + HttpUtility.UrlEncode(category.Name) + ".aspx";
            DataList.Add(data);
        }
        List.DataSource = DataList;
        List.DataBind();
    }

    public class Data
    {
        private string _Title;
        public string Title
        {
            get { return _Title; }
            set { _Title = value; }
        }
        private string _Url;
        public string Url
        {
            get { return _Url; }
            set { _Url = value; }
        }
        private string _FeedUrl;
        public string FeedUrl
        {
            get { return _FeedUrl; }
            set { _FeedUrl = value; }
        }        
    }    
}
